package com.scalar.forecast.salesPersonSetup.actionCommands;

import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.scalar.forecast.actionCommands.ActionCommand;
import com.scalar.forecast.commons.SessionKeys;
import com.scalar.forecast.salesPersonSetup.dao.SalesPersonSetupDAO;
import com.scalar.forecast.salesPersonSetup.forms.SalesPersonSetupForm;

/** Process the request to display sales person setup screen
 *
 * Created by Gandhi.
 * Date: Feb 8, 2005
 * Time: 6:30:52 PM
 */
public class SalesPersonSetupNewCommand extends ActionCommand {

    public ActionForward execute( ActionMapping mapping,
                                  ActionForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response ) //throws ScalarException
    {


        SalesPersonSetupForm salesPersonSetupForm = (SalesPersonSetupForm)form;
        HashMap errors = new HashMap ();
        try
        {
                request.setAttribute("salesPersonList", SalesPersonSetupDAO.getSalesPersonList());
                request.setAttribute("userList", SalesPersonSetupDAO.getUserList());
                request.setAttribute("levelList", SalesPersonSetupDAO.getLevelList());
                ArrayList mgrList = new ArrayList();
                request.setAttribute("mgrList", mgrList);
                ArrayList salesPersonsList = SalesPersonSetupDAO.loadSalesPersonsList( null );
                if ( salesPersonsList.size() > 0  )
                {
                    request.setAttribute("showList", "true");
                    request.setAttribute("salesPersonsList",  salesPersonsList );
                }

        }
        catch(Exception e)
        {
                System.out.println("-----------Exception in Sales Person Setup New Command-------------");
                errors.put ("Could not load sales person info from data base", null);
                request.setAttribute(SessionKeys.ERROR_MESSAGES, errors);
                e.printStackTrace();
        }
        ActionForward actionForward = mapping.findForward( "salesPersonSetup" );
        return actionForward;
    }

}
